package com.zcf.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.zcf.common.json.Body;
import com.zcf.common.json.Meta;
import com.zcf.common.utils.MD5Util;
import com.zcf.controller.SendSms;
import com.zcf.gameController.F_Websocket_s;
import com.zcf.gameController.WebSocketBull;
import com.zcf.mapper.UserMapper;
import com.zcf.pojo.*;
import com.zcf.utils.EmojiFilter;
import com.zcf.utils.PropertiesUtil;
import com.zcf.vo.out.LayuiJson;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhaoQi
 * @since 2019-03-18
 */
@Service
public class UserServiceImpl {

	@Autowired
	UserMapper um;
	@Autowired
	UserRecordServiceImpl userRecordService;
	@Autowired
	RechargeServiceImpl rechargeService;

	public UserBean selectByid(Long userid) {
		User user = new User();
		UserBean userBean = new UserBean();
		user.setId(userid);
		User user1 = user.selectById();
		if(user1!=null){
			BeanUtils.copyProperties(user1,userBean);
		}else{
			userBean = null;
		}
		return userBean;
	}
	/**
	 *微信登录
	 * @param user
	 * @return
	 */
	@SuppressWarnings("unused")
	public Body wxLogin(User user,HttpServletRequest request,HttpSession session) {
		System.out.println(user);
		if(user.getOpenid() == null && user.getOpenid() == "" ){
			return  Body.newInstance(421,"账号不能为空");
		}
		EntityWrapper<User> m = new EntityWrapper<User>();
		m.eq("openid", user.getOpenid());
		m.setSqlSelect("openid","nickname as wxname","avatarurl as wximg","sex","money","diamond","userid as id","isLogin","password","state");
		User user1 = user.selectOne(m);
		System.out.println(user1);
		if(user1 == null){
			User user2 = new User();
			user2.setOpenid(user.getOpenid());
			user2.setWximg(user.getWximg());
			if (user.getWxname().length()>6){
				user2.setWxname(user.getWxname().substring(0,6));
			}else {
				user2.setWxname(user.getWxname());
			}
			user2.setSex(user.getSex());
			user2.setIsPay(0);
			user2.setState(0);
			user2.setIp(getIpAddress(request));
			user2.setAddress(user.getAddress());
			user2.setDiamond(5000);
			user2.setMoney(10000);
			user2.setCreatetime(new Date());
			user2.setZcfUser(666);
			Integer in = um.insert(user2);
			if(in != 0){
				return Body.newInstance(user2);
			}else{
				return Body.BODY_451;
			}
		}else{
			Body reconnection = reconnection(user1);
			if(reconnection!=null){
				return reconnection;
			}
			user1.setIp(getIpAddress(request));
			user1.setAddress(user.getAddress());
			user1.setCreatetime(new Date());
			boolean b = user1.updateById();
			if (b){
				//登录人ID，用于作为key
				String userID = user.getId()+"";
				//session的ID，用于作为value
				String sessionID = request.getRequestedSessionId();
				//判断全局类中是否有该用户id的key，如果没有则添加，如果有且session不同，更换session的id为当前登录人的session的id

			}
			return b ? Body.newInstance(user1) : Body.newInstance(305, "登录失败");
		}
	}
	/**
	 *手机登录
	 * @param user
	 * @return
	 */
	@SuppressWarnings("unused")
	public Body phoneLogin(User user,HttpServletRequest request,HttpSession session) {
		if(StringUtils.isBlank(user.getPhone())){
			return  Body.newInstance(421,"手机号不能为空");
		}
		EntityWrapper<User> m = new EntityWrapper<User>();
		m.eq("phone", user.getPhone());
		m.setSqlSelect("phone","nickname as wxname","avatarurl as wximg","sex","money","diamond","userid as id","isLogin","password","state");
		User user1 = user.selectOne(m);
		if(user1 == null){
			return Body.newInstance(422,"账号不存在！");
		}
		Body reconnection = reconnection(user1);
		if(reconnection!=null){
			return reconnection;
		}
		if (!MD5Util.MD5EncodeUtf8(user.getPassword()).equals(user1.getPassword())){
			return  Body.newInstance(423,"密码错误！");
		}
		if (StringUtils.isEmpty(user1.getWxname())){
			user1.setWxname(user1.getPhone());
		}
		user1.setIp(getIpAddress(request));
		user1.setAddress(user.getAddress());
		user1.setCreatetime(new Date());
		boolean b = user1.updateById();
		return b ? Body.newInstance(user1) : Body.newInstance(305, "登录失败");
	}
	/**
	 * 判断用户状态
	 * @param user
	 * @return
	 */
	public Body reconnection(User user){
		if(user.getState() != null && user.getState() == 1){
			return  Body.newInstance(300,"账号已被冻结，请联系管理员");
		}


		/*if(WebSocketBull.clients.containsKey(user.getId()+"")){
			return Body.newInstance(new Meta(300,"账号已在游戏中"),user);
		}

		if(F_Websocket_s.clients.containsKey(user.getId()+"")){
			return Body.newInstance(new Meta(300,"账号已在游戏中"),user);
		}*/
		/*String roomName;
		HashMap<String, Object> map = new HashMap<>();
		Map<String, RoomsParam> rooms = WebSocketBull.rooms;
		for (RoomsParam room:rooms.values()) {
			roomName = room.getRoomName();
			Map<String, UserBean> users = room.getUsers();
			for (UserBean u:users.values()) {
				if(String.valueOf(u.getId()).equals(String.valueOf(user.getId()))  && u.getType() == 2){//如果
					map.put("roomName",roomName);
					map.put("user",user);
					user.setRoomName(roomName);
					return Body.newInstance(new Meta(111,"账号正在游戏中，是否重连"),user);
				}

			}
		}
		Map<String, Game_club> rooms2 = WebSocketBull.Rooms;
		for (Game_club club : rooms2.values()) {
			for (RoomsParam param : club.getClubs().values()) {
				if(param.getUsers().get(user.getId())!=null ){
					map.put("roomName",param.getRoomName());
					map.put("user",user);
					map.put("clubName", param.getClubName());
					user.setRoomName(param.getRoomName());
					return Body.newInstance(new Meta(111,"账号正在游戏中，是否重连"),user);
				}
			}
		}*/

		return null;
	}

	/**
	 * 编辑用户姓名
	 * @param user
	 * @return
	 */
	public Body updateName(User user){
		if(user.getId() == null){
			return Body.BODY_451;
		}

		User user1 = user.selectById();
		System.out.println(user1);
		if (StringUtils.isNotEmpty(user.getWxname())&&user.getWxname().length()>6||user.getWxname().length()<2){
			return  Body.newInstance(300,"昵称不能超过六位");
		}
		boolean b1 = EmojiFilter.containsEmoji(user.getWxname());
		if (b1){
			return  Body.newInstance(300,"昵称不能有表情！");
		}
		if (user1.getWxname().equals(user.getWxname())){
			return  Body.newInstance(300,"昵称不能重复！");
		}
		user1.setWxname(user.getWxname());
		boolean b = user1.updateById();
		return b ? Body.newInstance(Meta.CODE_200,user1.getWxname()): Body.BODY_451;
	}
		/**
		* @description :昵称
		* @param user
		* @date : 2019/11/21 14:42
		* @author : jj
		*/
	public Body updatePhoto(User user){
		if(user.getId() == null){
			return Body.BODY_451;
		}
		User user1 = user.selectById();
		if (user1.getWximg().equals(user.getWximg())){
			return  Body.newInstance(300,"头像没有变化！");
		}
		user1.setWximg(user.getWximg());
		boolean b = user1.updateById();
		return b ? Body.newInstance(Meta.CODE_200,user.getWximg()): Body.BODY_451;
	}
	/**
	 * 切换用户、退出
	 * @param user
	 * @return
	 */
	public Body exit(User user) {
		if(WebSocketBull.userMap.containsKey(user.getId()+"")){
			WebSocketBull.userMap.remove(user.getId()+"");
		}
		User user1 = um.selectOne(user);
		if(user1 != null ){
			user1.setIsLogin(0);
			boolean b = user1.updateById();
			if(b){
				return Body.BODY_200;
			}
		}
		return Body.BODY_451;
	}
	/**
	 * 编辑用户头像、昵称
	 * @param user
	 * @return
	 */
	public Body update(User user){
		int money=0;
		if(user.getId() != null){
			User user1 = user.selectById();
			if(user.getPassword() != null){
				user.setPassword(MD5Util.MD5EncodeUtf8(user.getPassword()));
				user1.setPassword(user.getPassword());
			}
			if(user.getState() != null){
				user1.setState(user.getState());
			}
			if(user.getMoney() != null){
				money = user.getMoney() - user1.getMoney();
				user1.setMoney(user.getMoney());
				Recharge recharge=new Recharge();
				recharge.setUserid(user1.getId());
				recharge.setMoney(money);
				recharge.setCreateTime(new Date());
				recharge.insert();
			}
			if(user.getIsPay() != null){
				user1.setIsPay(user.getIsPay());
			}
			user1.setText_1(user.getText_1());
			boolean b = user1.updateById();
			if(b){
				return Body.newInstance(money);
			}
		}
		return Body.BODY_451;
	}
	/**
	 * 获取用户列表
	 * @param user
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public LayuiJson getUsers(User user, int pageNum, int pageSize) {
		LayuiJson lj = new LayuiJson();
		Wrapper<User> w = new EntityWrapper<User>();
		List<String> list1 = new ArrayList<String>();
		list1.add("createtime");
		if (user.getPhone()!=null&&user.getPhone()!=""){
			w.eq("phone",user.getPhone()).or().eq("nickname ",user.getPhone()).or().eq("userid ",user.getPhone());
		}
		
		w.orderDesc(list1);
		List<User> list = um.selectPage(new Page<>(pageNum, pageSize), w);
		for (User user1:list){
			Long id = user1.getId();
			int sum = userRecordService.userSum(id);
			user1.setNumber1(sum);
			int sum2 = rechargeService.userSumRecharges(id);
			user1.setNumber2(sum2);
		}
		Integer count = um.selectCount(w);
		if (list != null) {
			lj.setCode(0);
			lj.setCount(count);
			lj.setData(list);
			lj.setMsg("成功");
			return lj;
		}
		lj.setCode(1);
		lj.setCount(count);
		lj.setData(null);
		lj.setMsg("暂无数据");
		return lj;
	}
	/**
	 * 删除某个用户
	 * @param user
	 * @return
	 */
	public Body delete(User user) {
		boolean b = user.deleteById();
		if(b){
			Game_club club = new Game_club();
			List<Game_club> list = club.selectList(new EntityWrapper<Game_club>().eq("founder", user.getId()));
			if(list!=null){
				for (Game_club game_club : list) {
					game_club.deleteById();
				}
			}
			ClubUser clubUser = new ClubUser();
			List<ClubUser> list2 = clubUser.selectList(new EntityWrapper<ClubUser>().eq("userid", user.getId()));
			if(list2!=null){
				for (ClubUser clubUser2 : list2) {
					clubUser2.deleteById();
				}
			}
			return Body.BODY_200;
		}
		return Body.BODY_451;
	}

	/**
	 * 获取某个用户
	 * @return
	 */
	public Body getUser(Long userid) {
		User user = new User();
		user.setId(userid);
		User user1 = user.selectById();
		return Body.newInstance(user1.getMoney());
	}

	public static String getIpAddress(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("HTTP_CLIENT_IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("HTTP_X_FORWARDED_FOR");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}
	public String getAddressByIP(String strIP)
	{
		try
		{
			URL url = new URL( "http://ip.qq.com/cgi-bin/searchip?searchip1=" + strIP);
			URLConnection conn = url.openConnection();
			BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "GBK"));
			String line = null;
			StringBuffer result = new StringBuffer();
			while((line = reader.readLine()) != null)
			{
				result.append(line);
			}
			reader.close();
			strIP = result.substring(result.indexOf( "该IP所在地为：" ));
			strIP = strIP.substring(strIP.indexOf( "：") + 1);
			String province = strIP.substring(6, strIP.indexOf("省"));
			String city = strIP.substring(strIP.indexOf("省") + 1, strIP.indexOf("市"));
			return city;
		}
		catch( IOException e)
		{
			return "读取失败";
		}
	}

	public static String getAddresses(String content, String encodingString) throws UnsupportedEncodingException {
		// 这里调用pconline的接口
		String urlStr = "http://ip.taobao.com/service/getIpInfo.php";
		// 从http://whois.pconline.com.cn取得IP所在的省市区信息
		String returnStr = getResult(urlStr, content, encodingString);
		if (returnStr != null) {
			// 处理返回的省市区信息
			//	            System.out.println("IP====="+returnStr);
			String[] temp = returnStr.split(",");
			if(temp.length<3){
				return "0";                                        //无效IP，局域网测试
			}
			String region = (temp[5].split(":"))[1].replaceAll("\"", "");
			region = decodeUnicode(region);                        // 省
			//	            System.out.println("region = "+region);

			String country = "";
			String area = "";
			// String region = "";
			String city = "";
			String county = "";
			String isp = "";
			//	            System.out.println("temp的长度="+temp.length);
			for (int i = 0; i < temp.length; i++) {
				switch (i) {

				case 1:
					country = (temp[i].split(":"))[2].replaceAll("\"", "");
					country = decodeUnicode(country);            // 国家
					break;
				case 3:
					area = (temp[i].split(":"))[1].replaceAll("\"", "");
					area = decodeUnicode(area);                // 地区
					break;
				case 5:
					region = (temp[i].split(":"))[1].replaceAll("\"", "");
					region = decodeUnicode(region);            // 省份
					break;
				case 7:
					city = (temp[i].split(":"))[1].replaceAll("\"", "");
					city = decodeUnicode(city);                // 市区
					break;
				case 9:
					county = (temp[i].split(":"))[1].replaceAll("\"", "");
					county = decodeUnicode(county);            // 地区
					break;
				case 11:
					isp = (temp[i].split(":"))[1].replaceAll("\"", "");
					isp = decodeUnicode(isp);                 // ISP公司
					break;
				}
			}
			//	            System.out.println(country+"="+area+"="+region+"="+city+"="+county+"="+isp);
			return region;
		}
		return null;
	}



	/**
	 * @param urlStr
	 *   请求的地址
	 * @param content
	 *   请求的参数 格式为：name=xxx&pwd=xxx
	 * @param encoding
	 *   服务器端请求编码。如GBK,UTF-8等
	 * @return
	 */
	private static String getResult(String urlStr, String content, String encoding) {
		URL url = null;
		HttpURLConnection connection = null;
		try {
			url = new URL(urlStr);
			connection = (HttpURLConnection) url.openConnection();// 新建连接实例
			connection.setConnectTimeout(3000);                     // 设置连接超时时间，单位毫秒
			connection.setReadTimeout(3000);                        // 设置读取数据超时时间，单位毫秒
			connection.setDoOutput(true);                           // 是否打开输出流 true|false
			connection.setDoInput(true);                            // 是否打开输入流true|false
			connection.setRequestMethod("POST");                    // 提交方法POST|GET
			connection.setUseCaches(false);                         // 是否缓存true|false
			connection.connect();                                   // 打开连接端口
			DataOutputStream out = new DataOutputStream(connection.getOutputStream());// 打开输出流往对端服务器写数据
			out.writeBytes(content);                                // 写数据,也就是提交你的表单 name=xxx&pwd=xxx
			out.flush();                                            // 刷新
			out.close();                                            // 关闭输出流
			BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding));// 往对端写完数据对端服务器返回数据 ,以BufferedReader流来读取
			StringBuffer buffer = new StringBuffer();
			String line = "";
			while ((line = reader.readLine()) != null) {
				buffer.append(line);
			}
			reader.close();
			return buffer.toString();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (connection != null) {
				connection.disconnect();                            // 关闭连接
			}
		}
		return null;
	}

	/**
	 * unicode 转换成 中文
	 *
	 * @author fanhui 2007-3-15
	 * @param theString
	 * @return
	 */
	public static String decodeUnicode(String theString) {
		char aChar;
		int len = theString.length();
		StringBuffer outBuffer = new StringBuffer(len);
		for (int x = 0; x < len;) {
			aChar = theString.charAt(x++);
			if (aChar == '\\') {
				aChar = theString.charAt(x++);
				if (aChar == 'u') {
					int value = 0;
					for (int i = 0; i < 4; i++) {
						aChar = theString.charAt(x++);
						switch (aChar) {
						case '0':
						case '1':
						case '2':
						case '3':
						case '4':
						case '5':
						case '6':
						case '7':
						case '8':
						case '9':
							value = (value << 4) + aChar - '0';
							break;
						case 'a':
						case 'b':
						case 'c':
						case 'd':
						case 'e':
						case 'f':
							value = (value << 4) + 10 + aChar - 'a';
							break;
						case 'A':
						case 'B':
						case 'C':
						case 'D':
						case 'E':
						case 'F':
							value = (value << 4) + 10 + aChar - 'A';
							break;
						default:
							throw new IllegalArgumentException(
									"Malformed  encoding.");
						}
					}
					outBuffer.append((char) value);
				} else {
					if (aChar == 't') {
						aChar = '\t';
					} else if (aChar == 'r') {
						aChar = '\r';
					} else if (aChar == 'n') {
						aChar = '\n';
					} else if (aChar == 'f') {
						aChar = '\f';
					}
					outBuffer.append(aChar);
				}
			} else {
				outBuffer.append(aChar);
			}
		}
		return outBuffer.toString();
	}
	/**
	 * 用户扣金币
	 * @param user
	 */
	public void update1(User user) {
		um.updateById(user);
	}

	/**
	 * 用户扣金币
	 * @param user
	 */
	public void updateUser(User user) {
		um.updateById(user);
	}
	/**
	 * 用户注册
	 * @param user
	 * @return
	 */
	public Body register(User user ,String code,HttpServletRequest request) {
		HttpServletRequest httpRequest=(HttpServletRequest)request;
		HttpSession session = request.getSession();

		if(user.getPhone() != null){
			EntityWrapper<User> w = new EntityWrapper<User>();
			w.eq("phone", user.getPhone());
			User user1 =user.selectOne(w);
			if(user1 != null){
				return Body.newInstance(304, "手机号已被注册");
			}
		}
		Body body = isCode(code, user);
		if (body!=null){
			return body;
		}
		if (StringUtils.isBlank(user.getPassword())){
			return Body.newInstance(472,"密码不能为空");
		}
		String strBackUrl = "http://" + request.getServerName() //服务器地址
        + ":" 
        + request.getServerPort()           //端口号
        + httpRequest.getContextPath();   //项目名称
		System.out.println("路径"+strBackUrl);
		user.setCreatetime(new Date());
		user.setPassword(MD5Util.MD5EncodeUtf8(user.getPassword()));
        //user.setWximg(user.getWximg());
		user.setWxname(user.getPhone().substring(user.getPhone().length()-6,user.getPhone().length()));
		user.setDiamond(200);
		user.setMoney(500);
		boolean b = user.insert();
		if (b){
			session.removeAttribute("verifyCode");
		}
		return b?Body.newInstance(200,"注册成功！"): Body.newInstance(473,"注册失败");
	}
	/**
	 * 游戏统计
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public LayuiJson getusernum(int pageNum, int pageSize) {
		LayuiJson lj = new LayuiJson();
		Map<String, Integer> map = new HashMap<String, Integer>();
		User user = new User();
		int count = user.selectCount(new EntityWrapper<User>().eq("zcf_user", 666));
		int count0 = WebSocketBull.userMap.size();
		int count1 = F_Websocket_s.userMap.size();
		int counts=count0+count1;
		map.put("sumnum", count);
		map.put("isloginnum",counts);
		List<Map<String, Integer>> list = new ArrayList<Map<String,Integer>>();
		list.add(map);
		if(map != null){
			lj.setCode(0);
			lj.setCount(null);
			lj.setData(list);
			lj.setMsg("成功");
			return lj;
		}
		lj.setCode(1);
		lj.setCount(null);
		lj.setData(null);
		lj.setMsg("暂无数据");
		return lj;
	}

	/**
	 * 发送短信
	 * @param phone
	 * @return
	 */
	public Body SendContent(String phone) {
		if (StringUtils.isBlank(phone)){
			return 	Body.newInstance(473,"手机号为空！");
		}
		Random random = new Random();
		String roomName = String.valueOf(random.nextInt(899999)+100000);
		EntityWrapper<Proving> w = new EntityWrapper<Proving>();
		w.eq("phone", phone);
		Proving proving = new Proving();
		Proving one = proving.selectOne(w);
		if(one != null){
			one.setProving(String.valueOf(roomName));
			one.setCreateTime(new Date());
			one.updateById();
		}else{
			proving.setPhone(phone);
			proving.setProving(String.valueOf(roomName));
			proving.setCreateTime(new Date());
			proving.insert();
		}
		SendSms sms = new SendSms();
		String sendSms = sms.SendSms(roomName, phone);
		return StringUtils.isEmpty(sendSms) ?Body.newInstance(470,"验证码发送失败！")
				:Body.newInstance(200,"验证码发送成功！");
	}
	
	/**
	 * 找回密码
	 * @param user
	 * @return
	 */
	public Body restpassword(User user, String code,HttpServletRequest request) {
		HttpSession session=request.getSession();
		if(!StringUtils.isBlank(user.getPassword())){
			User user2 = user.selectOne(new EntityWrapper<User>().eq("phone", user.getPhone()));
			if(user2!=null){
				Body body = isCode(code, user);
				if (body!=null){
					return body;
				}
				user2.setPassword(MD5Util.MD5EncodeUtf8(user.getPassword()));
				boolean b = user2.updateById();
				if(b){
					return Body.newInstance(200,"找回密码成功！");
				}
			}
		}
		
		return Body.newInstance(401,"找回密码错误！");
	}

	/**
	 * 代理编辑
	 * @param user
	 * @return
	 */
	public Body editagent(User user) {
		if(user.getId()!=null && user.getRole() != null){
			User user2 = user.selectById();
			user2.setRole(user.getRole());
			boolean b = user2.updateById();
			if(b){
				Agent agent = new Agent();
				Agent agent2 = agent.selectOne(new EntityWrapper<Agent>().eq("userid", user.getId()));
				if(user.getRole() == 1){
					if(agent2 != null){
						return Body.newInstance(401, "已经是代理");
					}else{
						agent.setType(1);
						agent.setUserid(user.getId().intValue());
						agent.setCreateTime(new Date());
						agent.insert();
					}
				}else{
					if(agent2 != null){
						agent2.deleteById();
					}else{
						return Body.newInstance(401, "不是代理");
					}
				}
			}
		}
		return Body.BODY_200;
	}

	/**
	 * @description :验证码判断
	 * @param code
	 * @param user
	 * @date : 2019/11/8 16:13
	 * @author : jj
	 */
	private  Body isCode(String code ,User user){

		Proving one;
		if(StringUtils.isNotEmpty(code)){
			Proving proving1 = new Proving();
			one = proving1.selectOne(new EntityWrapper<Proving>().eq("phone", user.getPhone()));
			if(one == null){
				return Body.newInstance(477, "验证码与手机不匹配");
			}
			Date date = new Date();
			long time1 = date.getTime();
			int time = (int) (time1 - one.getCreateTime().getTime())/1000/60;
			if(time >= 10){
				return Body.newInstance(450, "验证码已过期");
			}
			if(!one.getProving() .equals(code)){
				return Body.newInstance(470, "验证码错误");
			}
		}else{
			return Body.newInstance(471, "验证码不能为空");
		}
		return null;
	}



}